<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<link rel="stylesheet" href="resources/css/office/cheobang.css">
<script type="text/javascript"
	src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script type="text/javascript">
	var cheobang_id = "";
	$(document).ready(function() {
		$('#sss').click(function() {
			window.location.href = 'cheobangjeon.do?cheobang_id='+ cheobang_id2;
		});
		$("#inputtag").focus();
		$('.nameTr').hover(function() {
		$(this).css("background-color","silver");
		$(this).find('input').css("border"," silver");
		//$(this).find('input').css("padding", "1px");
		$(this).find('input').css("background-color","silver");
		},
		
		function() {
			$(this).css("background-color",
					"white");
			$(this).find('input').css("border",
					" white");
			/* $(this).find('input').css(
					"padding", "1px"); */
			$(this).find('input')
					.css("background-color",
							"white");
		})
			$("#btncheckname").click(function() {
				//alert("sss");
				var name = $("#inputtag").val();
				//alert(name);
				$.ajax({
					url : "cheobangcheck.do",
					data : "NAME=" + name,
					dataType : "json",
					success : function(data) {
						$("#sidetable")
								.empty();
						$("#sidetable")
								.html(
										"<tr><th>접수번호</th><th>이름</th></tr>");
						for (var i = 0; i < data.list.length; i++) {
							var name = data.list[i].name;
							var jupsoo_id = data.list[i].jupsoo_ID;
							var cheobang_id = data.list[i].cheobang_ID;
							var html = "<tr class='nameTr' ondblclick='dbclick(this);'>"
									+ "<td><input type='hidden' class='selectjupsoo_id' readonly='readonly' value='"+jupsoo_id+"'>"
									+ "<input type='hidden' id='cheobang_id' class='cheobang_id' name='cheobang_id' value='"+cheobang_id+"' readonly='readonly'>"+jupsoo_id+"</td>"
									+ "<td><input type='hidden' class='selectname' readonly='readonly' value='"+name+"'>"+name+"</td>"
									+ "</tr>";
							$('#sidetable').append(html);
						}
					},
					error : function(data) {
						//alert("fail");
					}
				});
			});
		});
	
	var cheobang_id2 = "";

	function dbclick(aaaa) {
		var idx = "";
		idx = $(".nameTr").index(aaaa);
		var name = $('.selectname').eq(idx).val();
		var jupsoo_id = $('.selectjupsoo_id').eq(idx).val();
		var cheobang_id = $(".cheobang_id").eq(idx).val();
		$.ajax({
					url : 'cheobanginfo.do',
					data : 'NAME=' + name + '&JUPSOO_ID=' + jupsoo_id
							+ '&CHEOBANG_ID=' + cheobang_id,
					dataType : 'json',
					success : function(data) {
						if (data.ch[0].is_WARD == 'Y') {
							alert("입원이 필요한 환자 입니다");
						}
						cheobang_id2 = data.ch[0].cheobang_id;
						$("#no_soonaptable").empty();
						var nosoonapobj = "<tr><th>처방번호</th><th>처방일자</th><th>진료과</th><th>미 수납금액</th></tr>";

						$("#no_soonaptable").html(nosoonapobj);
						var html6 = "<tr>" + "<td>" + data.nosoonap.cheobang_id
								+ "</td>" + "<td>" + data.nosoonap.jupsoo_date
								+ "</td>" + "<td>" + data.nosoonap.dept_name
								+ "</td>" + "<td>"
								+ data.nosoonap.remainder_price + "</td></tr>";
						var fsubmitbtn = "<input type='hidden' name='cheobang_id' value='"+data.nosoonap.cheobang_id+"'>";
						$("#soonapform").append(fsubmitbtn);
						$("#no_soonaptable").append(html6);
						$("#soonaptable").empty();
						var sooobj = "<tr><th>수납번호</th><th>급여총금액</th><th>비급여총금액</th><th>전체총금액</th><th>가감후총금액</th></tr>";
						$("#soonaptable").html(sooobj);
						var html5 = "<tr>" + "<td>" + data.soo.soonap_id
								+ "</td>" + "<td>" + data.soo.ok_sg_price
								+ "</td>" + "<td>" + data.soo.no_sg_price
								+ "</td>" + "<td>" + data.soo.total_price
								+ "</td>" + "<td>" + data.soo.total_sg_price
								+ "</td></tr>";
						$("#soonaptable").append(html5);
						$("#righttable3").empty();

						var htmlobj2 = "<tr>" + "<th>복용법</th>" + "</tr>";
						$("#righttable3").html(htmlobj2);
						for (var i = 0; i < data.doselist.length; i++) {
							var html4 = "<tr><td>" + data.doselist[i].dose_name
									+ "</td>" + "</tr>"
									+ "<tr><th>설명</th></tr>" + "<tr><td>"
									+ data.doselist[i].dose_explain
									+ "</td></tr>";
							$("#righttable3").append(html4);
						}
						;
						$("#righttable").empty();
						var htmlobj = "<tr>"
								+ "<th>약코드</th><th>약이름</th><th>가격</th><th>수량</th><th>내/외복</th>"
								+ "<th>단위</th></tr>";
						$("#righttable").html(htmlobj);
						for (var i = 0; i < data.mediclist.length; i++) {
							var html3 = "<tr><td>"
									+ data.mediclist[i].medicine_id + "</td>"
									+ "<td>" + data.mediclist[i].name + "</td>"
									+ "<td>" + data.mediclist[i].fee + "</td>"
									+ "<td>" + data.mediclist[i].quantity
									+ "</td>" + "<td>"
									+ data.mediclist[i].explain + "</td>"
									+ "<td>" + data.mediclist[i].unit
									+ "</td></tr>";
							$("#righttable").append(html3);
						}
						;
						$(".patiend_table").empty();

						/* <th style="width: width:95px;"></th>
						<td style="width: width:85px;"></td>
						<th style='width: width:72px;'></th>
						<td style='width: width:154px;'></td> */
						var html2 = "<tr>"
								+ "<th style='width:95px;'>처방 완료 번호</th>"
								+ "<td style='width:85px;'>"
								+ data.ch[0].cheobang_id
								+ "</td>"
								+ "<th  style='width:72px;'>접수번호</th>"
								+ "<td style='width:154px;'>"
								+ data.ch[0].jupsoo_ID
								+ "</td>"
								+ "</tr>"
								+ "<tr>"
								+ "<th>접수날짜</th>"
								+ "<td>"
								+ data.ch[0].jupsoo_DATE
								+ "</td>"
								+ "<th>접수시간</th>"
								+ "<td>"
								+ data.ch[0].jupsoo_TIME
								+ "</td>"
								+ "</tr>"
								+ "<tr>"
								+ "<th>초재진여부</th>"
								+ "<td>"
								+ data.ch[0].is_WARD
								+ "</td>"
								+ "<th>공휴일여부</th>"
								+ "<td>"
								+ data.ch[0].is_HOLIDAY
								+ "</td>"
								+ "</tr>"
								+ "<tr>"
								+ "<th>야간여부</th>"
								+ "<td>"
								+ data.ch[0].is_NIGHT
								+ "</td>"
								+ "<th>보험타입</th>"
								+ "<td>"
								+ data.ch[0].type
								+ "</td>"
								+ "</tr>"
								+ "<tr>"
								+ "<th>외래/입원 여부</th>"
								+ "<td>"
								+ data.ch[0].jupsoo_CODE_ID
								+ "</td>"
								+ "<th>첨부파일</th>"
								+ "<td>"
								+ data.ch[0].addfile
								+ "</td>"
								+ "</tr>"
								+ "<tr>"
								+ "<th>내원자번호</th>"
								+ "<td>"
								+ data.ch[0].visitant_ID
								+ "</td>"
								+ "<th>환자번호</th>"
								+ "<td>"
								+ data.ch[0].patient_ID
								+ "</td>"
								+ "</tr>"
								+ "<tr>"
								+ "<th>대분류</th>"
								+ "<td>"
								+ data.ch[0].habitat_ID
								+ "</td>"
								+ "<th>소분류</th>"
								+ "<td>"
								+ data.ch[0].content
								+ "</td>"
								+ "</tr>"
								+ "<tr>"
								+ "<th>상세분류</th>"
								+ "<td>"
								+ data.ch[0].habitat_DETAIL_ID
								+ "</td>"
								+ "<th>검사번호</th>"
								+ "<td>"
								+ data.ch[0].geomsa_CODE_ID
								+ "</td>"
								+ "</tr>"
								+ "<tr>"
								+ "<th>의사 고유번호</th>"
								+ "<td>"
								+ data.ch[0].doctor_ID
								+ "</td>"
								+ "<th>담당 의사</th>"
								+ "<td>"
								+ data.ch[0].doctor_NAME
								+ "</td>"
								+ "</tr>"
								+ "<tr>"
								+ "<th>부서번호</th>"
								+ "<td>"
								+ data.ch[0].dept_ID
								+ "</td>"
								+ "<th>부서이름</th>"
								+ "<td>"
								+ data.ch[0].dept_NAME + "</td>" + "</tr>";
						$(".patiend_table").append(html2);
						for (var d = 0; d < data.ch.length; d++) {
							var disease = "<tr>" + "<th>병명코드</th>" + "<td>"
									+ data.ch[d].disease_ID + "</td>"
									+ "<th>병명</th>" + "<td>"
									+ data.ch[d].disease_NAME + "</td>"
									+ "</tr>";
							$(".patiend_table").append(disease);
						}
						var opinion = "<tr><th>의사소견</th><td colspan='3'><textarea rows='3' cols='45' readonly style='border:0px; font-size:8pt;resize:none;'>"
								+ data.ch[0].opinion + "</textarea></td></tr>"
						$(".patiend_table").append(opinion);

						var html = /* "<tr id='patient_info_tr1'>" */
						"<td>" + data.patient.patient_id + "</td>" + "<td>"
								+ data.patient.name + "</td>" + "<td>"
								+ data.patient.gender + "</td>" + "<td>"
								+ data.patient.jumin1 + "-"
								+ data.patient.jumin2 + "</td>" + "<td>"
								+ data.patient.is_kuk + "</td>" + "<td>"
								+ data.patient.is_car + "</td>" + "<td>"
								+ data.patient.is_san + "</td>";
						/* +"</tr>"; */

						var html2 = /* "<tr id='patient_info_tr2'>" */
						"<td>" + data.patient.zipcode1 + "-"
								+ data.patient.zipcode2 + "</td>" + "<td>"
								+ data.patient.addr1 + " " + data.patient.addr2
								+ "</td>" + "<td>" + data.patient.tel + "</td>";
						/* +"</tr>" */
						$('#patient_info_tr1').empty().append(html);
						$('#patient_info_tr2').empty().append(html2);
					}

				});
		$('#sidejson').empty();
		var detachlist = "";

		detachlist += "<table id='sidetable'><tr><th>접수번호</th><th>이름</th></tr>";
		detachlist += "<c:forEach items='${list}' var='n' >";
		detachlist += "<tr class='nameTr'><td><input type='text' class='selectname' readonly='readonly' value='${n.JUPSOO_ID}'></td>";
		detachlist += "<td><input type='text' class='selectname' readonly='readonly' value='${n.NAME }'></td>";
		detachlist += "<input type='hidden' id='cheobang_id' class='cheobang_id' name='cheobang_id' value='${n.CHEOBANG_ID }'></tr></c:forEach></table>";

		$('#sidejson').append(detachlist);
	};

	function formaction(data) {
		var result = confirm('금액을 확인한 후 확인을 눌러주세요');
		if(result){
			if (data == "final") {
				var no_soonap_btn = $("#no_soonap_btn").val();
				//alert(no_soonap_btn)
				soonapform.action = "nosoonapsubmit.do?no_soonap_btn="
						+ no_soonap_btn;
				soonapform.submit();
			}
		}else{
			return false;
		}
		
	}

	/* 모달 스크립트 */
	$(document).ready(function() {
		idxcheck = function(aaaa) {
			var idx = $('.pname').index(aaaa);
			$("#inputtag").val($('.pname').eq(idx).val());
			$("#namelist").hide();
		}
		$('.login-window').click(function() {

			//Getting the variable's value from a link 
			var loginBox = $(this).attr('href');

			//Fade in the Popup
			$(loginBox).fadeIn(300);

			//Set the center alignment padding + border see css style
			var popMargTop = ($(loginBox).height() + 24) / 2;
			var popMargLeft = ($(loginBox).width() + 24) / 2;

			$(loginBox).css({
				'margin-top' : -popMargTop,
				'margin-left' : -popMargLeft
			});

			// Add the mask to body
			$('body').append('<div id="mask"></div>');
			$('#mask').fadeIn(300);

			return false;
		});

		// When clicking on the button close or the mask layer the popup closed
		$('a.close, #mask').live('click', function() {
			$('#mask , .login-popup').fadeOut(300, function() {
				$('#mask').remove();
			});
			return false;
		});
	});

	var name;
	function fn_onkeypress() {
		name = $("#inputtag").val();
		$("#namelist").show();
		if(name == ""){
			$("#namelist").hide();
		}
		var namelist;
		$
				.ajax({
					url : "cheobangcheck2.do",
					data : "NAME=" + name,
					dataType : "json",
					success : function(data) {
						$("#namelist").empty();
						if (typeof namelist == "undefined") {
							namelist = "";
						}
						for (var k = 0; k < data.list.length; k++) {
							namelist = "<div class='patient_name' name='patient_name'><input type='text' class='pname' name='pname' value='"
									+ data.list[k].name
									+ "' readonly='readonly' onclick='idxcheck(this);'></div>";
							$("#namelist").append(namelist);
						}

					},
					error : function(data) {
					//	alert("fail");
					}
				});
	}
</script>

<div id="systembase">
	<!-- 환자 정보 시작 -->
	<fieldset style="width: 950px;">
		<legend>환자정보</legend>
		<table class="patiend_info_table">
			<tr>
				<th class="width80px">고유번호</th>
				<th>이름</th>
				<th class="width80px">성별</th>
				<th class="width171px">주민번호</th>
				<th class="width80px">국민보험</th>
				<th class="width80px">자동차보험</th>
				<th class="width80px">산업재해보험</th>
			</tr>
			<tr id="patient_info_tr1">
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
			</tr>
		</table>
		<table class="patiend_info_table2">
			<tr>
				<th class="width171px">우편번호</th>
				<th>주소</th>
				<th class="width171px">연락처</th>
			</tr>
			<tr id="patient_info_tr2">
				<td></td>
				<td></td>
				<td></td>
			</tr>
		</table>
	</fieldset>
	<!-- 환자 정보 끝 -->
	<!-- 여긴 최근 환자 진료 정보 시작 -->
	<fieldset style="width: 408px; height: 476px;">
		<legend>처방 받은 내역</legend>
		<table class="patiend_table">
			<tr id="cheobanginfo">
				<th style="width: 95px;"></th>
				<td style="width: 85px;"></td>
				<th style="width: 72px;"></th>
				<td style="width: 154px;"></td>
			</tr>
			<tr>
				<th></th>
				<td></td>
				<th></th>
				<td></td>
			</tr>
			<tr>
				<th></th>
				<td></td>
				<th></th>
				<td></td>
			</tr>
			<tr>
				<th></th>
				<td></td>
				<th></th>
				<td></td>
			</tr>
			<tr>
				<th></th>
				<td></td>
				<th></th>
				<td></td>
			</tr>
			<tr>
				<th></th>
				<td></td>
				<th></th>
				<td></td>
			</tr>

			<tr>
				<th></th>
				<td></td>
				<th></th>
				<td></td>
			</tr>
			<tr>
				<th></th>
				<td></td>
				<th></th>
				<td></td>
			</tr>
			<tr>
				<th></th>
				<td></td>
				<th></th>
				<td></td>
			</tr>
			<tr>
				<th></th>
				<td></td>
				<th></th>
				<td></td>
			</tr>
			<tr>
				<th></th>
				<td colspan="3"></td>
			</tr>
		</table>
	</fieldset>
	<fieldset style="width: 502px;">
		<legend>약 처방 정보</legend>
		<table id="righttable">
			<tr>
				<th>약코드</th>
				<th>약이름</th>
				<th>가격</th>
				<th>수량</th>
				<th>내/외복</th>
				<th>단위</th>
			</tr>
			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
			</tr>
		</table>
	</fieldset>
	<fieldset style="width: 502px;">
		<legend>복용법</legend>
		<table id="righttable3">
			<tr>
				<th>복용법</th>
			</tr>
			<tr>
				<td></td>
			</tr>
			<tr>
				<th>설명</th>
			</tr>
			<tr>
				<td></td>
			</tr>
		</table>

	</fieldset>
	<fieldset style="width: 502px;">
		<legend>진료 총 금액</legend>
		<table id="soonaptable">
			<tr>
				<th>수납번호</th>
				<th>급여총금액</th>
				<th>비급여총금액</th>
				<th>전체총금액</th>
				<th>가감후총금액</th>
			</tr>
			<tr id="soonap">
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
			</tr>

		</table>
	</fieldset>
	<!-- 오른쪽 아래 끝 -->
	<form action="">
		<div id='sss'>
			<a target="_blank" style="cursor: pointer">처방 출력하기</a> | <a
				href="#login-box" class="login-window" id='soonap_href_id'>수납하기</a>
		</div>
	</form>
</div>
<!-- 여긴 최근 환자 진료 정보 끝 -->




<!-- 오른쪽 환자 대기 리스트 시작 -->
<div id="systembaseside">
	<div id='namelist' style="display: none;"></div>
	<div style="text-align: center; margin: 20px auto;">
		<input id="inputtag" class="inputtag" type="text" name="name2"
			onkeyup="fn_onkeypress();">
		<button type="button" id="btncheckname" name="btncheckname">검색</button>
	</div>
	<div
		style="text-align: center; font-size: 14pt; font-weight: bold; margin: 10px;">치료
		완료 리스트</div>
	<div id='sidejson'>
		<table id="sidetable">
			<tr>
				<th>접수번호</th>
				<th>이름</th>
			</tr>
			<c:forEach items="${list}" var="n">
				<tr class='nameTr'>
					<td><input type='hidden' class='selectname' readonly='readonly'
						value='${n.JUPSOO_ID}'><input type="hidden"
						id="cheobang_id" name="cheobang_id" value="${n.CHEOBANG_ID }">${n.JUPSOO_ID}</td>
					<td><input type='hidden' class='selectname' readonly='readonly'
						value='${n.NAME }'>${n.NAME }</td>
					
				</tr>
			</c:forEach>
		</table>
		<table class="sidetable">
		</table>
	</div>
	<%-- <input id="inputtag" type="text" name="name2" placeholder="환자 이름 검색"
		onkeyup="fn_onkeypress();"> <input type="button"
		id="btncheckname" name="btncheckname" value="검색">
	<hr>
	<h3 id="sidelist">치료 완료 리스트</h3>
	<br>
	<div id='sidejson'>
		<table id="sidetable">
			<tr>
				<td>이름</td>
				<td>접수번호</td>
			</tr>
			<c:forEach items="${list}" var="n">
				<tr class='nameTr'>
					<td><input type='text' class='selectname' readonly='readonly'
						value='${n.NAME }'></td>
					<td><input type='text' class='selectname' readonly='readonly'
						value='${n.JUPSOO_ID}'></td>
					<input type="hidden" id="cheobang_id" name="cheobang_id" value="${n.CHEOBANG_ID }">
				</tr>
			</c:forEach>
		</table>
		<table class="sidetable">

		</table>
	</div> --%>
</div>
<!-- 오른쪽 환자 대기 리스트 끝 -->
<div id="login-box" class="login-popup" style="clear: both;">
	<!-- 오른쪽 위 시작-->
	<div id="systemcontentright">
		<h3 id="systemmenufont">환자 미수납 정보</h3>
		<table id="no_soonaptable">
			<tr>
				<!-- <th>처방번호</th><th>처방일자</th><th>진료과</th><th>미 수납금액</th> -->
			</tr>
			<tr>
				<!-- <td></td><td></td><td></td><td></td> -->
			</tr>
		</table>
	</div>
	<!-- 오른쪽 위 끝 -->

	<!-- 오른쪽 아래 시작 -->
	<div id="systemcontentright">
		<h3 id="systemmenufont">수납하기</h3>
		<form id="soonapform" name="soonapform">
			<table id="righttable">
				<tr>
					<th>수납 금액</th>
					<td><input id="no_soonap_btn" name="no_soonap_btn" type="text"
						placeholder="수납금액 입력란"
						onkeyPress="if ((event.keyCode<48) || (event.keyCode>57)) event.returnValue=false;"></td>
				</tr>
				<tr>
					<td colspan="2"><button id="finalbtn" class="btn2"
							onclick="formaction('final')">완료</button></td>
				</tr>
			</table>
		</form>
	</div>
</div>